package edu.zut2.inner_demo;

public interface Operator {

    double sum(double a, double b);

    double sub(double a,double b);

}

class Test{

    public static void main(String[] args) {
        /**
         * 匿名内部类的使用：
         * 当实例化接口或抽象类时，需要通过{}将抽象方法全部进行实现，此时系统会默认给我们提供一个匿名内部类
         */
        Operator operator = new Operator(){
            @Override
            public double sum(double a, double b) {
                return a + b;
            }

            @Override
            public double sub(double a, double b) {
                return a - b;
            }
        };

        double sum = operator.sum(23, 56);
        double sub = operator.sub(56, 78);

    }

}



class A implements Operator{

    @Override
    public double sum(double a, double b) {
        return a + b;
    }

    @Override
    public double sub(double a, double b) {
        return 0;
    }

    public static void main(String[] args) {
        Operator operator = new A();
        double sum = operator.sum(25, 56);
        System.out.println("sum = " + sum);
    }

}
